import 'package:flutter/material.dart';

class DonationAmountOption {
  final String label;
  final double amount;
  final bool isSelected;
  final bool isDisabled;

  DonationAmountOption({
    required this.label,
    required this.amount,
    this.isSelected = false,
    this.isDisabled = false,
  });

  DonationAmountOption copyWith({
    String? label,
    double? amount,
    bool? isSelected,
    bool? isDisabled,
  }) {
    return DonationAmountOption(
      label: label ?? this.label,
      amount: amount ?? this.amount,
      isSelected: isSelected ?? this.isSelected,
      isDisabled: isDisabled ?? this.isDisabled,
    );
  }
}

class DonationAmountSelector extends StatelessWidget {
  final List<DonationAmountOption> options;
  final Function(DonationAmountOption) onOptionSelected;
  final double userBalance;
  final double remainingAmount;

  const DonationAmountSelector({
    super.key,
    required this.options,
    required this.onOptionSelected,
    required this.userBalance,
    required this.remainingAmount,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const Text(
            '选择捐赠金额',
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.bold,
            ),
          ),
          const SizedBox(height: 12),
          Wrap(
            spacing: 8,
            runSpacing: 8,
            children: options.map((option) {
              final isDisabled = option.isDisabled || 
                               userBalance < option.amount || 
                               remainingAmount < option.amount;
              
              return _buildAmountOption(option, isDisabled);
            }).toList(),
          ),
        ],
      ),
    );
  }

  Widget _buildAmountOption(DonationAmountOption option, bool isDisabled) {
    return GestureDetector(
      onTap: isDisabled ? null : () => onOptionSelected(option),
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
        decoration: BoxDecoration(
          color: isDisabled 
              ? Colors.grey[200]
              : option.isSelected 
                  ? Colors.green[100]
                  : Colors.white,
          border: Border.all(
            color: isDisabled
                ? Colors.grey[300]!
                : option.isSelected
                    ? Colors.green
                    : Colors.grey[300]!,
            width: 1,
          ),
          borderRadius: BorderRadius.circular(20),
        ),
        child: Text(
          option.label,
          style: TextStyle(
            color: isDisabled
                ? Colors.grey[400]
                : option.isSelected
                    ? Colors.green
                    : Colors.black87,
            fontSize: 14,
            fontWeight: option.isSelected ? FontWeight.bold : FontWeight.normal,
          ),
        ),
      ),
    );
  }
} 